package com.mofang;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.app.NotificationManager;

import com.pactera.framework.imgload.AsyncImageLoader;
import com.pactera.framework.imgload.BitmapCache;
import com.pactera.framework.util.ConfigProperties;
import com.pactera.framework.util.Loger;
import com.pactera.framework.util.MyApplication;
import com.pactera.framework.util.PictureUtil;
import com.umeng.analytics.MobclickAgent;

public class MoFangApplication extends MyApplication {

	// 百度定位所需
	// private String KEY = "EeE7ZPGBl9ky3WQv4dyUsuep";
	public static AsyncImageLoader asyncImageLoader = null;
	private List<Activity> activities = new ArrayList<Activity>();
	public static BitmapCache bitmapCache;
	public static Boolean isFinished = false;
	
	public static final Map<String, Object> dataShare=new HashMap<String, Object>();
	
	@Override
	public void onCreate() {
		super.onCreate();
	}
	
	

	public void addActivity(Activity activity) {
		activities.add(activity);
	}

	@Override
	public void onTerminate() {
		super.onTerminate();
		isFinished = true;
		clearActivitys();
		if (bitmapCache != null) {
			bitmapCache.clearMemoryCache();
			bitmapCache = null;
		}
		((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
				.cancelAll();
		activities = null;
		asyncImageLoader.clearWorks();
		asyncImageLoader.stopThreads();
		asyncImageLoader = null;
		System.exit(0);
	}

	public void clearActivitys() {
		for (Activity activity : activities) {
			if (activity != null) {
				Loger.d(activity.toString());
				activity.finish();
			}
		}
	}

	public static void asyncImageLoaderRecle() {
		asyncImageLoader.stopThreads();
		asyncImageLoader = new AsyncImageLoader(null, 3, 30);
	}
}
